package 异常;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

//运行异常，无需显示处理可以运行后处理
public class 编译和运行异常区别 {
    public static void main(String[] args) {
        method();
        method2();
    }

    //编译异常
    public static void method2() {
        try {
            String s = "2023-04-13";
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
            Date d = sdf.parse(s);
            System.out.println(d);
        } catch (ParseException e) {
            e.printStackTrace();
        }
    }

        //运行时异常
        public static void method () {
            try {
                int[] arr = {1, 2, 3};
                System.out.println(arr[3]);//ArrayIndexOutOfBoundsException
            } catch (ArrayIndexOutOfBoundsException e) {
                e.printStackTrace();
            }

            //编译时异常
        }

}